<?php

namespace App\Lib\Util;

/**
 * Class ErrorMessage
 *
 * @package App\Library
 */
class ErrorMessage
{
    /**
     * 接口错误默认信息，如果已标明，以标明的信息优先
     */
    static protected $defaultMessage = [
        ErrorCode::SUCCESS_CODE                 => '请求成功',
        ErrorCode::ERROR_CODE                   => '请求失败',

        //=============================================系统级错误信息===================================================//
        ErrorCode::UNKNOWN                      => '未知错误',
        ErrorCode::PARAMS_ERROR                 => '请求参数错误',
        ErrorCode::SERVER_ERROR                 => '服务器错误',
        ErrorCode::UNAUTHORIZED                 => '用户未认证',
        ErrorCode::FORBIDDEN                    => '用户无权限访问该资源',
        ErrorCode::NO_DATA                      => '没有数据了',
        ErrorCode::DEPRECATED                   => '此接口已废弃，请升级到新版本客户端',
        ErrorCode::NOT_READY                    => '正在建设中',
        ErrorCode::NOT_FOUND                    => '资源不存在',
        ErrorCode::CREATE_FAILED                => '添加失败',
        ErrorCode::DELETE_FAILED                => '删除失败',
        ErrorCode::UPDATE_FAILED                => '更新失败',
        ErrorCode::SELECT_FAILED                => '查找失败',
        ErrorCode::INVALID_CONFIG               => '配置错误',
        ErrorCode::ACTION_FAILED                => '操作失败',
        ErrorCode::SUBMIT_PARAMS_VALIDATE_ERROR => '提交数据验证失败',
        ErrorCode::NETWORK_ERROR                => '网络错误',
        ErrorCode::DB_ERROR                     => 'DB错误',
        ErrorCode::ROUTER_NOT_FUND              => '路由不存在',
        ErrorCode::SYSTEM_CTL_NOT_FOUND         => '控制器未找到',
        ErrorCode::SYSTEM_CTL_ACTION_NOT_FOUND  => '方法未找到',

        //=============================================企业微信通知相关========================================================//
        ErrorCode::EMPTY_MESSAGE                => '消息为空',
        ErrorCode::EMPTY_USER                   => '接受人为空',
        ErrorCode::GET_TOKEN_ERROR              => '获取token错误',
        ErrorCode::TOKEN_ERROR                  => 'token失效',
        ErrorCode::SEND_ERROR                   => '发送消息失败',
        ErrorCode::GET_USER_ERROR               => '获取用户列表错误',

        //=============================================用户相关========================================================//
        ErrorCode::INVITE_CODE_FAILED           => '生成bd邀请码失败',
        ErrorCode::INVALID_INVITE_CODE          => '无效的bd邀请码',

        //=============================================用户相关=====================================================//
        ErrorCode::AGENT_NOT_SIGN               => '代理尚未完成签约',


        //=============================================推送信息相关=====================================================//
        ErrorCode::INVILID_MESSAGE_ACTION       => '无效指令',


        //=============================================维护者相关=====================================================//
        ErrorCode::MAINTAINER_NO_RULE           => '获取配置的规则信息失败',
        ErrorCode::MAINTAINER_NO_GOODS_NO       => '获取商户的行为信息失败',
        ErrorCode::MAINTAINER_EVENT_TYPE_ERROR  => '获取商户行为的事件类型错误，未定义的枚举值'

    ];

    /**
     * @param int $errorCode
     * @return string
     */
    static public function getMessage(int $errorCode): string {
        return isset(self::$defaultMessage[$errorCode]) ? self::$defaultMessage[$errorCode] : '';
    }
}
